package plugproxy.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * addon utilities class
 */
public class AddonUtil {
    private static String HOSTS_IN_WINDOWS = "C:\\WINDOWS\\system32\\drivers\\etc\\hosts";
    private static String HOSTS_IN_WINNT = "C:\\WINNT\\system32\\drivers\\etc\\hosts";
    private static String HOSTS_IN_UNIX = "/etc/hosts";

    /**
     * get ip address for host
     *
     * @param host host
     * @return ip address
     */
    public static String getIpAddress(String host) {
        try {
            InetAddress address = InetAddress.getByName(host);
            return address.getHostAddress();
        } catch (UnknownHostException e) {
            return null;
        }
    }

    /**
     * validate wild match
     *
     * @param text    text
     * @param pattern pattern
     * @return matched mark
     */
    public static boolean isWildMatched(String text, String pattern) {
        pattern = pattern.replace(".", "\\.");
        pattern = pattern.replace("*", ".*");
        pattern = pattern.replace("?", ".?");
        return text.matches(pattern);
    }

    /**
     * insert fake host in hosts file
     *
     * @param host host name
     */
    public static void insertFakeHost(String host) {
    }

    /**
     * delete fake host from hosts file
     *
     * @param host host name
     */
    public static void deleteFakeHost(String host) {

    }
}
